<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Created by CodeTlan.
 * User: Ing. Miguel Salas
 * Date: 3/4/12
 * Time: 4:16 PM
 */
class CT_Model extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }

    function add($data,$table=false){
        $table=$table?$table:$this->table;
        return $this->db->insert($table,$data);//?$this->db->insert_id():false;
    }

    function edit($data,$tokens,$table=false){
        $table=$table?$table:$this->table;
        //$table?$table:$this->table;
        return $this->db->update($table,$data,$tokens);
    }

    function find($columns,$tokens,$start, $limit){

        $start= empty($start)?0:$start;

        $this->db->select($columns);
        $this->db->from($this->table);
        if(!empty($tokens))
            $this->db->where($tokens);
        $this->db->where('estatus = 1');
        $this->db->limit($limit,$start);

        $query=$this->db->get();
        $data= $query->result();


        $this->db->select($columns);
        $this->db->from($this->table);
        if(!empty($tokens))
            $this->db->where($tokens);
        $this->db->where('estatus = 1');
        $query= (object) $this->db->get();
        $numRows= $query->num_rows();

        return array("data"=>$data,"total"=>$numRows);
    }



}
